"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
var _a;
Object.defineProperty(exports, "__esModule", { value: true });
const mes_1 = __importDefault(require("../../utils/mes"));
class UserValidator {
}
_a = UserValidator;
UserValidator.regAndLogin = (req, res, next) => {
    try {
        const { name, pass } = req.body;
        if (!(name === null || name === void 0 ? void 0 : name.trim()))
            throw '请输入用户名';
        if (name.length < 3 || name.length > 6)
            throw '用户名长度为3~6位';
        if (!(pass === null || pass === void 0 ? void 0 : pass.trim()))
            throw '请输入密码';
        if (pass.length < 6 || pass.length > 12)
            throw '用户名长度为6~12位';
        next();
    }
    catch (error) {
        res.status(401).send(mes_1.default.failed(error));
    }
};
UserValidator.update = (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
    try {
        const { name, newName, newPass } = req.body;
        if (!(name === null || name === void 0 ? void 0 : name.trim()))
            throw '请输入要修改的用户名';
        if (name.length < 3 || name.length > 6)
            throw '用户名长度为3~6位';
        if (newName && (newName.length < 3 || newName.length > 6))
            throw '新用户名长度为3~6位';
        if (newPass && (newPass.length < 6 || newPass.length > 12))
            throw '新密码长度为6~12位';
        next();
    }
    catch (error) {
        res.status(401).send(mes_1.default.failed(error));
    }
});
UserValidator.delete = (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
    try {
        const { name } = req.body;
        if (!(name === null || name === void 0 ? void 0 : name.trim()))
            throw '请输入要删除的用户名';
        if (name.length < 3 || name.length > 6)
            throw '用户名长度为3~6位';
        next();
    }
    catch (error) {
        res.status(401).send(mes_1.default.failed(error));
    }
});
exports.default = UserValidator;
